<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../common/common-include.jsp" %>
<%@ include file="../common/jquery-easyui.jsp" %>

<!-- 数据列表 -->
<table id="dg" title="My List" class="easyui-datagrid" style="width:700px;height:300px"
		url="searchList.action"  
        toolbar="#toolbar" pagination="true"
        rownumbers="true" fitColumns="true" singleSelect="true">  
    <thead>  
        <tr>  
        	<th field="id" width="50" >ID</th>  
            <th field="listName" width="50"><s:text name="label.listName" /></th>  
            <th field="createBy" width="50"><s:text name="label.createBy" /></th>  
            <th field="createTs" width="50"><s:text name="label.createTs" /></th>  
        </tr>  
    </thead>  
</table>  

<!-- 功能按钮 -->
<div id="toolbar">  
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newList();">New</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editList();">Edit</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeList();">Remove</a>  
</div> 

<!-- 新建窗口 -->
 <div id="dlg" class="easyui-dialog" style="width:300px;height:180px;padding:10px 20px"  
            closed="true" buttons="#dlg-buttons">  
        <form id="fm" method="post" novalidate>  
            <div class="fitem">  
                <label><s:text name="label.listName" />:</label>  
                <input name="listName" class="easyui-validatebox" required="true">  
                <input name="id" type="hidden">  
            </div>  
        </form>  
</div>  
<div id="dlg-buttons">  
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveList()">Save</a>  
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">Cancel</a>  
</div>


<script type="text/javascript">
	var url;
	function newList() {
		$('#dlg').dialog('open').dialog('setTitle', 'New List');
		$('#fm').form('clear');
		url = 'addList.action';
	}

	function saveList() {
		$('#fm').form('submit', {
			url : url,
			onSubmit : function() {
				return $(this).form('validate');
			},
			success : function(result) {
				var result = eval('(' + result + ')');
				if (result.msg) {
					$.messager.show({
						title : 'Message',
						msg : result.msg
					});
				}
				$('#dlg').dialog('close'); // close the dialog  
				$('#dg').datagrid('reload'); // reload the user data  
			}
		});
	}

	function editList() {
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$('#dlg').dialog('open').dialog('setTitle', 'Edit List');
			$('#fm').form('load', row);
			url = 'updateList.action';
		}
	}

	function removeList() {
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$.messager.confirm('Confirm',
					'Are you sure you want to remove this list?', function(r) {
						if (r) {
							$.post('deleteList.action', {
								id : row.id
							}, function(result) {
								if (result.msg) {
									$.messager.show({ // show error message  
										title : 'Message',
										msg : result.msg
									});
								} 
							    $('#dg').datagrid('reload'); // reload the user data  
							}, 'json');
						}
					});
		}
	}
</script>



